﻿using System;
using System.Collections.Generic;

namespace RexToy.Cassandra
{
    class IntegerType : IMarshal
    {
        public byte[] GetBytes(object data)
        {
            if (data == null)
                return Constant.Zero_Length_Byte_Array;
            short i = (short)data;
            byte[] bytes = BitConverter.GetBytes(i);
            MarshalUtil.AdjustBufferOrder(bytes);
            return bytes;
        }

        public object GetData(byte[] bytes)
        {
            if (bytes.Length == 0)
                return null;

            MarshalUtil.AdjustBufferOrder(bytes);
            return BitConverter.ToInt16(bytes, 0);
        }
    }
}
